package com.dlg.user.rpc.api.vo.user;

import com.alibaba.fastjson.JSON;
import com.dlg.commons.enums.UserType;
import com.dlg.commons.exception.DataFindException;
import org.apache.commons.lang3.StringUtils;

/**
 * 用户注册api Vo
 * 
 * @author lhh@gongren.com
 * @since 2017年3月30日 上午9:41:56
 *
 */
public class UserRegisterRpcVo extends UserRpcVo {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 验证码
	 */
	private String vaildCode;



	/**
	 * 来源 register(自己注册)/generalize(活动推广)/recommend(用户推荐)
	 */
	private String source;
							
	/**
	 * 活动 活动全称首字母，如：平台返利活动，“ptfl”
	 */
	private String activity;
	
	/**
	 * 渠道 渠道名称，如：百度，“baidu”
	 */
	private String channel;
	
	/**
	 * 关键字
	 */
	private String ws; 
	
	/**
	 * 客户端类型 如：ANDROID、IOS、H5、PC 
	 */
	private String client; 
	
	/**
	 * app版本
	 */
	private String appVersion;
	
	/**
	 * 注册成功后是否默认登录0:false, 1:true
	 */
	private short isLogin = 0;

	private String distance;

	public String validate(){
		if (this == null) {
			return "注册对象为null";
		}
		if (null == this.getPhone()) {
			return "注册对象手机号为null";
		}
		if (null == this.getVaildCode() && !"offline".equals(this.getSource())) {
			return "验证码为null";
		}
		if (null == this.getPassword()) {
			return "注册对象密码为null";
		}
		if (null == this.getType()) {
			return "用户类型为null";
		}
		return null;
	}

	public String validateRegister(){
		if (this == null) {
			return "注册对象不能为空";
		}
		if (StringUtils.isEmpty(this.getSource())) {
			return "source不能为空";
		}
		if (StringUtils.isEmpty((this.getClient()))) {
			return "client不能为空";
		}
		if (StringUtils.isEmpty(this.getAppVersion())) {
			return "AppVersion不能为空";
		}
		if (StringUtils.isEmpty(this.getPhone())) {
			return "手机号不能为空";
		}
		if (null == this.getVaildCode() && !"offline".equals(this.getSource())) {
			return "验证码为不能为空";
		}
		if (!UserType.PERSONAL.equals(this.getType()) && !UserType.ENTERPRISE.equals(this.getType())) {
			return "用户类型非法";
		}
		if (null == this.getPassword() || this.getPassword().trim().length() < 6 || this.getPassword().trim().length() > 18) {
			return "密码长度应为6-18位";
		}
		return null;
	}
	
	public String getAppVersion() {
		return appVersion;
	}

	public void setAppVersion(String appVersion) {
		this.appVersion = appVersion;
	}

	public String getVaildCode() {
		return vaildCode;
	}

	public void setVaildCode(String vaildCode) {
		this.vaildCode = vaildCode;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public String getActivity() {
		return activity;
	}

	public void setActivity(String activity) {
		this.activity = activity;
	}

	public String getChannel() {
		return channel;
	}

	public void setChannel(String channel) {
		this.channel = channel;
	}

	public String getWs() {
		return ws;
	}

	public void setWs(String ws) {
		this.ws = ws;
	}

	public String getClient() {
		return client;
	}

	public void setClient(String client) {
		this.client = client;
	}
	

	public short getIsLogin() {
		return isLogin;
	}

	public void setIsLogin(short isLogin) {
		this.isLogin = isLogin;
	}

	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}

	public String getDistance() {
		return distance;
	}

	public void setDistance(String distance) {
		this.distance = distance;
	}
}
